package json;

import com.alibaba.fastjson.JSON;
import json.model.BcMonitorInfo;
import json.model.Login;
import json.model.Token;
import sun.jvm.hotspot.tools.SysPropsDumper;

/**
 * All rights Reserved, Designed By www.tusdao.com
 *
 * @version V1.0
 * @Title: JsonToObj.java
 * @Package json
 * @Description: TODO(用一句话描述该文件做什么)
 * @author: tusxxw
 * @date: 2020/8/28 4:40 下午
 * @Copyright: 2020 www.tbs.com Inc. All rights reserved.
 * <p>
 * 注意：本内容仅限于TBS项目组内部传阅，禁止外泄以及用于其他的商业目的
 */
public class JsonToObj {

    public static String jsonDataRep = "{\n" +
            "    \"status\": 200,\n" +
            "    \"success\": true,\n" +
            "    \"message\": \"You have successfully logged in!\",\n" +
            "    \"token\": \"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjoiYWRtaW4iLCJuZXR3b3JrIjoidGJzX2RlZmF1bHQiLCJpYXQiOjE1OTg1OTU3NDAsImV4cCI6MTU5ODYwMjk0MH0.6vaHr0jX6zW_gxIGo5lqPur2qFwikoK2qly4vmevHZc\",\n" +
            "    \"user\": {\n" +
            "        \"mess_Age\": \"logged in\",\n" +
            "        \"name\": \"admin\"\n" +
            "    }\n" +
            "}";

    public static String loginJson = "{\n" +
            "  \"user\": \"admin\",\n" +
            "  \"password\": \"adminpw\",\n" +
            "  \"network\": \"tbs_default\"\n" +
            "}";

    public static String bcJson = "{\"info\":{\"uuid\":\"2898663ff52b4152e8b6e7c500efec6ffc0192c720ad7ab3076f8a627c2e446b\",\"expIp\":\"192.168.1.110\"},\"data\":[{\"bc_block\":[{\"blockNum\":1,\"dataHash\":\"2898663ff52b4152e8b6e7c500efec6ffc0192c720ad7ab3076f8a627c2e446b\",\"preHash\":\"ea9f989308171748f9351cf8e6c8798d497ba5f0fa2468d5d98661510aead157\",\"createDt\":\"2020-08-31T08:10:19.326Z\",\"txCount\":2},{\"blockNum\":2,\"dataHash\":\"2898663ff52b4152e8b6e7c500efec6ffc0192c720ad7ab3076f8a627c2e446b\",\"preHash\":\"ea9f989308171748f9351cf8e6c8798d497ba5f0fa2468d5d98661510aead157\",\"createDt\":\"2020-08-31T08:10:19.326Z\",\"txCount\":2}],\"bc_chaincode\":[{\"chaincodeName\":\"xfs\",\"path\":\"/dev/sda3\",\"version\":\"1.0\",\"txCount\":\"9\",\"channelHash\":\"ea9f989308171748f9351cf8e6c8798d497ba5f0fa2468d5d98661510aead157\"},{\"chaincodeName\":\"xw\",\"path\":\"/dev/s\",\"version\":\"1.1\",\"txCount\":\"6\",\"channelHash\":\"2898663ff52b4152e8b6e7c500efec6ffc0192c720ad7ab3076f8a627c2e446b\"}],\"bc_tx\":[{\"txHash\":\"ea9f989308171748f9351cf8e6c8798d497ba5f0fa2468d5d98661510aead157\",\"createDt\":\"2020-08-31T08:10:19.326Z\",\"txContext\":\"2898663ff52b4152e8b6e7c500efec6ffc0192c720ad7ab3076f8a627c2e446b\"},{\"txHash\":\"ea9f989308171748f9351cf8e6c8798d497ba5f0fa2468d5d98661510aead157\",\"createDt\":\"2020-08-31T08:10:19.326Z\",\"txContext\":\"2898663ff52b4152e8b6e7c500efec6ffc0192c720ad7ab3076f8a627c2e446b\"}],\"bcName\":\"localdomain\",\"bcHash\":\"ea9f989308171748f9351cf8e6c8798d497ba5f0fa2468d5d98661510aead157\",\"blockCount\":200,\"txCount\":105,\"peerCount\":58,\"smcCount\":25}]}";
    public static void main(String[] args) {

        //json 转 对象
        Login login = JSON.parseObject(loginJson, Login.class);
        System.out.println(login);

        //对象转json
        login.setUser("xxw");
        String objToJson = JSON.toJSONString(login);
        System.out.println(objToJson);

        Token token = JSON.parseObject(jsonDataRep,Token.class);
        System.out.println(token);

        BcMonitorInfo bcMonitorInfo = JSON.parseObject(bcJson,BcMonitorInfo.class);
        System.out.println("-------BcMonitorInfo--------");
        System.out.println(bcMonitorInfo.getInfo());
        System.out.println(bcMonitorInfo.getBcData());


    }
}
